Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

http-response-object

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-response-object

A simple object to represent an http response

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is http-response-object?

The http-response-object npm package is a utility for creating and manipulating HTTP response objects. It provides a simple and consistent API for generating HTTP responses, making it easier to handle HTTP responses in Node.js applications.

What are http-response-object's main functionalities?

Creating a Response Object

This feature allows you to create a new HTTP response object with a specified status code, headers, and body. In this example, a response object with a 200 status code, JSON content type, and a JSON body is created.

const Response = require('http-response-object');
const response = new Response(200, { 'Content-Type': 'application/json' }, JSON.stringify({ message: 'Success' }));
console.log(response);

Accessing Response Properties

This feature allows you to access the properties of the response object, such as statusCode, headers, and body. The example demonstrates how to log these properties to the console.

const Response = require('http-response-object');
const response = new Response(200, { 'Content-Type': 'application/json' }, JSON.stringify({ message: 'Success' }));
console.log(response.statusCode); // 200
console.log(response.headers); // { 'Content-Type': 'application/json' }
console.log(response.body); // {"message":"Success"}

Modifying Response Headers

This feature allows you to modify the headers of an existing response object. In this example, a custom header is added to the response headers.

const Response = require('http-response-object');
let response = new Response(200, { 'Content-Type': 'application/json' }, JSON.stringify({ message: 'Success' }));
response.headers['X-Custom-Header'] = 'CustomValue';
console.log(response.headers); // { 'Content-Type': 'application/json', 'X-Custom-Header': 'CustomValue' }

Other packages similar to http-response-object

Keywords

FAQs

Package last updated on 15 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc